<?php
Box::$description["Watermark"] = "A watermarked container";
/**
*Draw a watermarked area that can superimpose or underimpose an image on another plugin.
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*@package Boxes
*@subpackage Watermark
*/
class Box_Watermark extends Box
{
	private $watermark = false;
	
	public function __construct( $title )
	{
		parent::__construct( $title, "inline","box:Watermark/Watermark" );
		$this->watermark = new Box_Image_Picture("watermark");
	}
	protected function PostInitialize()
	{
		$this->SetStorage(array("left" => "0px",
								"top" => "0px", 
								"z-index" => 1));
		$this->SetChild("content", "");
		$this->AddEditTab( "box:Watermark/WatermarkEdit",
							I18N("Configure watermark"),
							I18N("Save configuration"),
							"SaveWatermark" );
		$this->AddEditTab( 'string:{include file="core:atom_manager" input_name="content" atom_id=$children.content}',
							I18N("Select watermark content"),
							I18N("Select content"),
							"SaveContent" );
	}

	protected function ProcessData( $data )
	{
		$data["data"]["watermark_style"] = 
				"left:".$this->Get("left")
				.";top:".$this->Get("top")
				.";z-index:".($this->Get("z-index") == 0 ? 100 : 0)
				.";position:absolute;";
		return $this->watermark->ProcessData( $data );
	}

	protected function SaveWatermark( $request )
	{
		$r1 = $r2 = $r3 = false;
		if ( ($left = Core::PostVar("left", false, "string")) !== false )
			$r1 = $this->Set("left", $left);
		if ( ($top = Core::PostVar("top", false, "string")) !== false )
			$r2 = $this->Set("top", $top);
		if ( ($stack = Core::PostVar("stack", false, "string")) !== false )
			$r3 = $this->Set("z-index", ($stack == "b") ? 100:0 );

		if ( ($r1!==false) || ($r2!==false) || ($r3!==false) )
			$request->SetReload();

		$this->watermark->Save() && $request->SetReload();
		echo I18N("Saved ($left)-($top)-($stack).");
	}

	protected function SaveContent( $request )
	{
		$c = Core::PostVar("content", false, "string");
		if ( $c )
			$this->SetChild("content", $c ) && $request->SetReload();
		echo I18N("Page content modified!")." ($c)";
	}

}
?>